﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aliyeye.Car.Net.UI.PopupDialog;
using Aliyeye.Car.Net.Utility;
using Aliyeye.Car.Net.UI.Common;

namespace Aliyeye.Car.Net.UI.CarModel
{
    public partial class CarInfo : Aliyeye.Car.Net.UI.BaseForm
    {
        private bool isDriver = false;
        private int CarID = 0;
        DataSet dtDepart = null;
        DataSet dtRole = null;

        CarSvc.SoapHeaderClass sopaHeader = new CarSvc.SoapHeaderClass();

        public CarInfo()
        {
            InitializeComponent();
            this.Text = "车辆详细信息";
        }

        public CarInfo(bool isDri, int id)
        {
            InitializeComponent();
            isDriver = isDri;
            CarID = id;
            this.Text = "修改车辆信息";
        }

        private void BindInfo()
        {

            overlay.FadeIn();

            CarSvc.Car model = new Aliyeye.Car.Net.UI.CarSvc.Car();

            AccountsUsersSvc.Accounts_Users AccountsUserModel = new Aliyeye.Car.Net.UI.AccountsUsersSvc.Accounts_Users();
            AccountsUsersSvc.SoapHeaderClass sopaHeadercustomer = new Aliyeye.Car.Net.UI.AccountsUsersSvc.SoapHeaderClass(); ServiceManipulator.SafeAsyncExecution<CarSvc.CarServiceSoapClient>(
                proxy => proxy.GetModel(sopaHeader, CarID),
                result =>
                {
                    if (result.Error == null)
                    {
                        model = (CarSvc.Car)result.Result;


                        this.txtBuyPrice.Text = model.BuyPrice.ToString();
                        this.txtBuyTime.Text = model.BuyTime.ToString("yyyy-MM-dd");
                        this.txtInsureTime.Text = model.InsureTime.ToString("yyyy-MM-dd");
                        this.txtCartype.Text = model.Cartype;
                        this.txtCode.Text = model.Code.ToString();
                        this.txtTimeouter.Text = model.Color.ToString();
                        this.txtDecorate.Text = model.Decorate.ToString();
                        this.txtdipanCode.Text = model.dipanCode;
                        this.txtDrive.Text = model.Drive == true ? "带驾" : "自驾";
                        if (model.Drive)
                        {
                            this.txtdayrent.Visible = true;
                            this.lbldayrent.Visible = true;
                        }
                        else
                        {
                            this.txtdayrent.Visible = false;
                            this.lbldayrent.Visible = false;

                        }
                        this.txtEndbridge.Text = model.Endbridge.ToString("yyyy-MM-dd");
                        this.txtEndOpen.Text = model.EndOpen.ToString("yyyy-MM-dd");
                        this.txtEndCare.Text = model.EndCare.ToString("yyyy-MM-dd");
                        this.txtEndChenshui.Text = model.EndChenshui.ToString("yyyy-MM-dd");
                        this.txtEndOpen.Text = model.EndOpen.ToString("yyyy-MM-dd");
                        this.txtEndyunguan.Text = model.Endyunguan.ToString("yyyy-MM-dd");
                        this.txtFactorCode.Text = model.FactorCode;
                        this.txtInsureEnd.Text = model.InsureEnd.ToString("yyyy-MM-dd");
                        this.txtInsureTime.Text = model.InsureTime.ToString("yyyy-MM-dd");
                        this.txtMotorCode.Text = model.MotorCode;
                        this.txtcolor.Text = model.Color;
                        //model.Max = max;
                        this.txtOvertimePrie.Text = model.OvertimePrie.ToString();
                        this.txtOwners.Text = model.Owners;
                        this.txtOwnerTel.Text = model.OwnerTel;
                        this.txtRoadEnd.Text = model.RoadEnd.ToString("yyyy-MM-dd");
                        this.txtRoadTime.Text = model.RoadTime.ToString("yyyy-MM-dd");
                        this.txtSeat.Text = model.Seat;
                        this.textShangpaishui.Text = model.Shangpaishui.ToString();
                        this.txtStarbridge.Text = model.Starbridge.ToString("yyyy-MM-dd");
                        this.txtStarCheshui.Text = model.StarCheshui.ToString("yyyy-MM-dd");
                        this.txtStarMax.Text = model.StarMax.ToString();
                        this.txtStaryunguan.Text = model.Staryunguan.ToString("yyyy-MM-dd");
                        this.txtTax.Text = model.Tax.ToString();

                        this.txtBrand.Text = model.Cartype;
                        this.txtMax.Text = model.Max.ToString();
                        this.txtCareTime.Text = model.CareTime.ToString("yyyy-MM-dd");
                        this.txtStarOpen.Text = model.StarOPen.ToString("yyyy-MM-dd");
                        this.txtBrand.Text = model.Brand;

                        this.txtCarTime.Text = model.FactoryOutDate.ToString("yyyy-MM-dd");
                        this.txtwarrtime.Text = model.WarrTime.ToString("yyyy-MM-dd"); ;
                        this.txtmarks.Text = model.Marks;
                        this.txtTimeouter.Text = model.TimeoutPrie.ToString();
                        this.txtdayrent.Text = model.DayRent.ToString();
                        this.txtdaykm.Text = model.DayKm.ToString(); ;
                        this.txtsendmile.Text = model.SendMile.ToString();
                        this.txtnextsend.Text = model.NextMile.ToString();


                        this.txtuseid.Text = model.DriverName;
                        overlay.FadeOut();
                    }
                    else
                    {
                        PageCommon.Error(result.Error.Message); overlay.FadeOut();
                    }
                },
                this
            );

            //ServiceManipulator.SafeAsyncExecution<AccountsUsersSvc.Accounts_UsersServiceSoapClient>(
            //    proxy => proxy.GetModel(sopaHeadercustomer, model.UserId),
            //    result =>
            //    {
            //        if (result.Error == null)
            //        {
            //            AccountsUserModel = (AccountsUsersSvc.Accounts_Users)result.Result;
            //            if (AccountsUserModel != null)
            //            {
            //                this.txtuseid.Text = AccountsUserModel.TrueName;

            //            }

            //            overlay.FadeOut();
            //        }
            //        else
            //        {
            //            PageCommon.Error(result.Error.Message); overlay.FadeOut();
            //        }
            //    },
            //    this
            //);
        }

        private void AddUsers_Load(object sender, EventArgs e)
        {
            BindComboBoxInfo();
            if (CarID != 0)
                BindInfo();
        }

        private void BindComboBoxInfo()
        {
            BLL.Accounts_Roles bllRole = new BLL.Accounts_Roles();
            string strWhere = string.Empty;

            dtRole = bllRole.GetList(strWhere);

            BLL.Base_Department bllDepart = new BLL.Base_Department();
            dtDepart = bllDepart.GetList("");
        }

        //关闭
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private string GetDepartmentName(int departID)
        {
            if (dtDepart != null)
            {
                DataRow[] drs = dtDepart.Tables[0].Select(" ClassID ='" + departID + "'");
                return drs[0]["ClassName"].ToString();
            }
            else
            {
                return "";
            }
        }

        private string GetRoleName(int roleID)
        {
            if (dtDepart != null)
            {
                DataRow[] drs = dtRole.Tables[0].Select(" RoleID ='" + roleID + "'");
                return drs[0]["Description"].ToString();
            }
            else
            {
                return "";
            }
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            //  UserList UserList = new UserList(isDriver, userID);
            // UserList.ShowDialog();
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnModify_Click_1(object sender, EventArgs e)
        {
            AddCarsNew AddCarsForm = new AddCarsNew(isDriver, Convert.ToInt32(CarID));
            AddCarsForm.ShowDialog();

        }

        private void label41_Click(object sender, EventArgs e)
        {

        }






    }
}
